<template>
  <el-card class="box-card" shadow="never">
    <template #header>
      <div class="card-header">
        <img src="../../assets/img/applyList.png" style="width: 50px;height: 50px;">
        <span>申请列表</span>
      </div>
    </template>
    <el-row :gutter="10">
      <el-col :span="4">
        <el-input placeholder="请输入用户名称" v-model="searchContent"></el-input>
      </el-col>
      <el-col :span="4">
        <el-button type="primary" @click="handleSearch()">搜索</el-button>
      </el-col>
    </el-row>
    <el-table :data="tableData" :model="user_name" style="width: 100%">
      <el-table-column label="编号" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.ID }}</span>
        </template>
      </el-table-column>
      <el-table-column label="姓名" width="180">
        <template #default="scope">
          <el-popover effect="light" trigger="hover" placement="top">
            <template #reference>
              <div class="name-wrapper">
                <el-tag size="medium">{{ user_name }}</el-tag>
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="预约名称" width="180">
        <template #default="scope">
          <el-popover effect="light" trigger="hover" placement="top">
            <template #reference>
              <div class="name-wrapper">
                <el-tag size="medium">{{ scope.row.reservation_name }}</el-tag>
              </div>
            </template>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="资源" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.resource_id }}</span>
        </template>
      </el-table-column>
      <el-table-column label="资源类型" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.resource_type }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核记录" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.check_msg }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.status }}</span>
        </template>
      </el-table-column>
      <el-table-column label="描述" width="180">
        <template #default="scope">
          <el-icon><timer /></el-icon>
          <span style="margin-left: 10px">{{ scope.row.describe }}</span>
        </template>
      </el-table-column>
    </el-table>
  </el-card>
  <el-pagination
      v-model:currentPage="currentPage"
      :page-sizes="[3, 5, 10, 20]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="useSizeChange"
      @current-change="useCurrentChange"
  >
  </el-pagination>
</template>

<script>
import axios from "axios";
import {reactive, onMounted, toRefs} from "vue";
import rsSubsidy from  "../front_desk/ReservationSubsidy.vue"
function loaData(state){
  const params = {
    page:state.currentPage,
    limit:state.pageSize,
    search_content:state.searchContent,
    user_id:localStorage.getItem("ID"),
    user_name:localStorage.getItem("user")
  }
  axios.get("/api/reservationUsers", {params},).then((res) => {
    state.tableData = res.data.data.res.data
    state.total = res.data.data.res.total //总记录数
  })
}
//监听pageSize改变的事件
function useHandleSizeChange(state){
  const useSizeChange = (pageSize) => {
    console.log(pageSize)
    state.pageSize = pageSize
    loaData(state)
  }
  return {
    useSizeChange
  }
}
//监听当前页面切换的事件
function useHandleCurrentPage(state){
  const useCurrentChange = (page) => {
    console.log(page)
    state.currentPage = page
    loaData(state)
  }
  return {
    useCurrentChange,
  }
}
//申请详情
function useEdit(state){
  const handleEdit = (index) => {
    state.editProductVisible = true;
    state.sId = index
  }
  return {
    handleEdit
  }
}
export default {
  name: "FrontSubsidy",
  components:{
    rsSubsidy
  },
  setup(){
    const state = reactive({
      tableData: [],
      user_name: localStorage.getItem("user"),
      dialogVisible: false,//控制新增的窗口
      editProductVisible: false,//控制编辑的窗口
      total: 0,
      currentPage: 1,
      pageSize: 4,
      searchContent: "",//模糊搜索的内容
      sId: 0
    });
    const url = import.meta.env.VITE_APP_URL
    onMounted(() => {
      console.log("lll")
      loaData(state)
    });
    //关闭编辑用户
    const closeEditDialogVisible = (visible) => {
      loaData(state)
      state.editProductVisible = visible;
    }
    return {
      ...toRefs(state),
      ...useHandleSizeChange(state),
      ...useHandleCurrentPage(state),
      ...useEdit(state),
      closeEditDialogVisible
    }
  }
}
</script>

<style scoped>
.items {
  display: flex;
  /*flex-wrap属性，wrap(包裹)根据大小设置一行放多少个，nowrap,都放一行 */
  flex-wrap: wrap;
  justify-content: space-around;
  /* position: relative; */
}
.item {
  position: relative;
  width: 18%;
}
.aa {
  margin-left: 50px;
  margin-right: 50px;
}
.img-wrap {
  width: 200px;
  height: 200px;
  background-color: #409eff;
  font-size: 10px;
  margin-top: 20px;
}
.img-wrap img {
  width: 100%;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 18px;
  opacity: 0.75;
  line-height: 300px;
  margin: 0;
  text-align: center;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}

</style>